package com.example.bbang.Interceptor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 添加Web项目的拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 对所有访问路径，都通过MyInterceptor类型的拦截器进行拦截
//        registry.addInterceptor(new UserInterceptor()).addPathPatterns("/**")
//              .excludePathPatterns("/user/login","/user/register","/user/logout","/money/add",
//                      "/order/byid","/redisTest/getUserByusername","/img/**","/upload/img/**");//,"/**"
        //.excludePathPatterns放行登录页，登陆操作，静态资源
    }

    /**
     * 图片保存路径，自动从yml文件中获取数据
     *   示例： E:/images/
     */
    @Value("${file-save-path}")
    private String fileSavePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * 配置资源映射
         * 意思是：如果访问的资源路径是以“/img/”开头的，
         * 就给我映射到本机的“E:/images/”这个文件夹内，去找你要的资源
         * 注意：E:/images/ 后面的 “/”一定要带上
         */
        registry.addResourceHandler("/img/**")
                .addResourceLocations("file:"+fileSavePath);
//        registry.addResourceHandler("/img/**")
//                .addResourceLocations("classpath:/static/img/");
    }


}
